package com.yxhl.zoume.core.busticket.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.yxhl.protobuf.OneYxBusInfoRequest;
import com.yxhl.zoume.R;
import com.yxhl.zoume.common.ui.activity.base.BaseActivityWithToolBar;
import com.yxhl.zoume.core.busticket.ui.fragment.ZouMeBusOrderFragment;
import com.yxhl.zoume.core.func.webpage.info.WebPageEntrance;
import com.yxhl.zoume.di.component.base.HasComponent;
import com.yxhl.zoume.di.component.busticket.BusServiceComponent;
import com.yxhl.zoume.di.component.busticket.DaggerBusServiceComponent;
import com.yxhl.zoume.di.module.busticket.BusServiceModule;


public class ZouMeBusOrderActivity extends BaseActivityWithToolBar implements HasComponent<BusServiceComponent> {
    private static final String INTENT_EXTRA_PARAM_ZOUMEBUS_DETAIL = "INTENT_EXTRA_PARAM_ZOUMEBUS_DETAIL";

    BusServiceComponent component;
    OneYxBusInfoRequest param;

    /**
     * intent for navigation
     *
     * @param context
     * @param param
     * @return
     */
    public static Intent getCallingIntent(Context context, OneYxBusInfoRequest param) {
        Intent callingIntent = new Intent(context, ZouMeBusOrderActivity.class);
        callingIntent.putExtra(INTENT_EXTRA_PARAM_ZOUMEBUS_DETAIL, param);
        return callingIntent;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent intent = getIntent();
        if (null != intent) {
            Bundle bundle = intent.getExtras();
            param = (OneYxBusInfoRequest) bundle.getSerializable(INTENT_EXTRA_PARAM_ZOUMEBUS_DETAIL);
        }

        addFragment(R.id.zoume_bus_order_container, ZouMeBusOrderFragment.newInstance(param));
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_zoume_bus_order;
    }

    @Override
    protected void initializeInjector() {
        this.component = DaggerBusServiceComponent.builder()
                .appComponent(getAppComponent())
                .activityModule(getActivityModule())
                .busServiceModule(new BusServiceModule())
                .build();
    }

    @Override
    protected void onHeaderLeftClick(View view) {
        onBackPressed();
    }

    @Override
    protected void onHeaderRightClick(View view) {
        getAppComponent().navigator().navigateToWebPageActivity(this, WebPageEntrance.ZOU_ME_BUS_INTRODUCTION);
    }

    @Override
    public BusServiceComponent getComponent() {
        return component;
    }
}
